package com.tian.controller;

import com.tian.pojo.Honor;
import com.tian.service.HonorService;
import com.tian.vo.PageResult;
import com.tian.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/honor")
@CrossOrigin
public class HonorController {
    @Autowired
    private HonorService honorService;
    //获取数据
    @GetMapping("/honorList")
    public SysResult getList(PageResult pageResult){
        pageResult = honorService.getList(pageResult);
        return SysResult.success(pageResult);
    }
    //根据ID获取数据
    @GetMapping("/{id}")
    public SysResult gethonorById(@PathVariable Integer id){
        Honor honor = honorService.getById(id);
        return SysResult.success(honor);
    }

    @DeleteMapping("/delete/{id}")
    public SysResult deleteById(@PathVariable Integer id) {
        honorService.deleteById(id);
        return SysResult.success();
    }




    //修改请求
     @PutMapping("/updataHonor")
        public SysResult updataHonor(@RequestBody Honor honor){
         System.out.println(honor);
        honorService.updataHonor(honor);
        return SysResult.success();
    }
    //添加请求
     @PostMapping("/addHonor")
    public SysResult addHonor(@RequestBody Honor honor){
        if(honor.getHonorname()==""||honor.getHonormessage()==""||honor.getHonortime()==null)
            return SysResult.fail();
        honorService.addHonor(honor);
        return SysResult.success();
    }

}
